<?php
/**
 * string helper
 * Date: 2019年3月21日
 * Time: 下午12:00:59
 */
namespace app\common\service\Helper;

class Str
{
    /**
     * 获取指定长度的随机字母数字组合的字符串
     *
     * @param  int $length
     * @return string
     */
    public static function random($length = 16,string $pool = '')
    {
        $pool = !empty($pool) ? $pool : '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
        
        return \think\helper\Str::substr(str_shuffle(str_repeat($pool, $length)), 0, $length);
    }
    /**
     * 将字符串中间部分隐藏为***
     *
     * @param  string $str
     * @return string
     */
    public static function make_star($str = '')
    {
        if($str){
            $len = mb_strlen($str,'utf-8');
            $a = mb_substr($str,1,$len-2,'utf-8');
            $str = str_replace($a,'***',$str);
        }
        return $str;
    }
}